package cn.wolfcode.luowowo.shop.service.impl;

import cn.wolfcode.luowowo.shop.domain.ShopRoll;
import cn.wolfcode.luowowo.shop.mapper.ShopRollMapper;
import cn.wolfcode.luowowo.shop.query.ShopRollQuery;
import cn.wolfcode.luowowo.shop.service.IShopRollService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class ShopRollServiceImpl implements IShopRollService {
  
    @Autowired
    private ShopRollMapper shopRollMapper;

    @Override
    public PageInfo query(ShopRollQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<ShopRoll> list = shopRollMapper.selectAll();
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(ShopRoll shopRoll) {
        if(shopRoll.getId()==null){
            shopRollMapper.insert(shopRoll);
        }else {
            shopRollMapper.updateByPrimaryKey(shopRoll);
        }
    }

    @Override
    public void delete(Long id) {
        shopRollMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<ShopRoll> getTop5() {
        List<ShopRoll> list = new ArrayList<>();
        list = shopRollMapper.getTop5();
        return list;
    }

}
